package com.dovgopoly.carlogbook.web.login.client.view;

import com.dovgopoly.carlogbook.common.mvp.AbstractView;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

public class LoginViewimpl extends AbstractView<LoginView.Presenter> implements LoginView {

	private static LoginViewimplUiBinder uiBinder = GWT.create(LoginViewimplUiBinder.class);
	@UiField
	Button btnLogin;
	@UiField
	TextBox textUsername;
	@UiField
	TextBox textPassword;
	@UiField
	Button btnRegister;

	interface LoginViewimplUiBinder extends UiBinder<Widget, LoginViewimpl> {
	}

	public LoginViewimpl() {
		initWidget(uiBinder.createAndBindUi(this));
	}

	public LoginViewimpl(String firstName) {
		initWidget(uiBinder.createAndBindUi(this));

	}

	@UiHandler("btnLogin")
	void onBtnLoginClick(ClickEvent event) {
		presenter.login(textUsername.getText(), textPassword.getText());
	}

	@UiHandler("btnRegister")
	void onBtnRegisterClick(ClickEvent event) {
		presenter.showRegistrationForm();
	}
}
